#ifndef BASEMANAGER_H
#define BASEMANAGER_H

#include <QObject>
#include <QMap>
#include "messagequeue.h"

typedef void (*CallFunc)(void *me, QEvent const *event);

#define MANAGER_TRANS(obj) (reinterpret_cast<BaseManager::CallFunc>(obj))

class BaseManager : public QObject
{
    Q_OBJECT
public:
    BaseManager(QObject *parent = nullptr);
    virtual ~BaseManager() override;

    void publish(QEvent* event);
    void publish(QObject *obj, QEvent* event);
    void subscribe(quint16 id, QObject* who);
    void unsubscribe(quint16 id, QObject* who);

protected:
    void transform(void (*func)(void *me, const QEvent *event));

    static void quit(BaseManager *me, QEvent const *event);

    virtual void customEvent(QEvent *event) override;

private:
    MessageQueue m_messageQueue;

    CallFunc callFunc = nullptr;
};

#endif // BASEMANAGER_H
